<?php
// 用户模型
class UserModel extends CommonModel {
	public $_validate	=	array(
		array('account','/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/','帐号格式错误'),
		array('password','require','密码必须'),
                array('password','pwdLength','密码长度为5-20位',self::EXISTS_VAILIDATE,'callback',self::MODEL_BOTH),
		array('nickname','require','昵称必须'),
		array('repassword','require','确认密码必须'),
		array('repassword','password','确认密码不一致',self::EXISTS_VAILIDATE,'confirm'),
		array('account','','帐号已经存在',self::EXISTS_VAILIDATE,'unique',self::MODEL_INSERT),
		);

	public $_auto		=	array(
		array('password','pwdHash',self::MODEL_BOTH,'callback'),
		array('cTime','time',self::MODEL_INSERT,'function'),
		array('uTime','time',self::MODEL_UPDATE,'function'),
		);

	protected function pwdLength() {
		if(strlen($_POST['password'])<'5' || strlen($_POST['password'])>'20') {
			return false;
		}else{
			return true;
		}
	}

        protected function pwdHash() {
		if(isset($_POST['password'])) {
			return pwdHash($_POST['password']);
		}else{
			return false;
		}
	}
}
?>